package com.zhumo.sz.service.impl;

import com.alibaba.fastjson.*;
import com.zhumo.sz.common.CommonInsert;
import com.zhumo.sz.common.CustomLogServerConfig;
import com.zhumo.sz.common.http.HttpClientHelper;
import com.zhumo.sz.common.utils.DateFormatUtil;
import com.zhumo.sz.common.utils.RandomUtil;
import com.zhumo.sz.config.AddressConfig;
import com.zhumo.sz.entity.subway.*;
import com.zhumo.sz.entity.user.UserInfo;
import com.zhumo.sz.gaode.*;
import com.zhumo.sz.mapper.SubwayMapper;
import com.zhumo.sz.mapper.UserMapper;
import com.zhumo.sz.mock.RandomGenerator;
import com.zhumo.sz.mock.TrafficMocker;
import com.zhumo.sz.service.SubwayService;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.HttpClient;
import org.apache.http.entity.ContentType;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author jiaqi.zhu
 * @comment  修改日志 v1.0 2023-03-13 初始化地铁流量
 *                   v1.1 2023-03-23 重构生成逻辑 
 */
@Service
@Slf4j
public class SubwayServiceImpl implements SubwayService {


    @Autowired
    private SubwayMapper subwayMapper;

    @Autowired
    private UserMapper userMapper;

    private static GaoDeAddressProcessor gaoDeAddressProcessor;

    /**
     * 初始化处理器
     */
    public static void InitProcessor() {
        if (gaoDeAddressProcessor != null) {
            if (gaoDeAddressProcessor.getApplicationKey().length() != 32) {
                throw new IllegalArgumentException("高德应用key传递有误");
            }
        } else {
            //默认使用注册的应用key
            gaoDeAddressProcessor = new GaoDeAddressProcessor(CustomLogServerConfig.GaoDE_APPLICATION_KEY);
        }
    }

    /**
     * 获取地铁站点信息
     * 业务逻辑 请求所有站点 -> 地理编码获取经纬度 -> 地理逆编码获取poi -> 封装结果 -> 写入MySQL
     * 结果的poi类型和权重 如何 poi 封装成json类型
     */
    @Override
    public CommonInsert<SubwayStationInfo> setSubwayStationInfo(int page, int rows) {
        //获取所有站点信息
        String subwayStationUrl = "https://opendata.sz.gov.cn/api/29200_00403624/1/service.xhtml";
        HttpClient client = HttpClientHelper.createDefault();
        HashMap<String, Object> stationParmMap = new HashMap<>();
        stationParmMap.put("appKey", CustomLogServerConfig.OPENDATA_SZ_APP_KEY);
        stationParmMap.put("page", String.valueOf(page));
        stationParmMap.put("rows", String.valueOf(rows));
        JSONObject stationResponse = HttpClientHelper.sendJsonGetRequest(subwayStationUrl, AddressConfig.ContentTypeJsonHeader, stationParmMap,
                ContentType.APPLICATION_JSON, client);
        String responseRow = stationResponse.getString("rows");
        if (Objects.nonNull(responseRow) && responseRow.equals(String.valueOf(rows))) {
            List<SubwayStationInfo> collect = stationResponse.getJSONArray("data").stream().map(
                    data -> {
                        SubwayStationInfo subwayStationInfo = new SubwayStationInfo();
                        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(data));
                        String id = jsonObject.getString("ID");
                        subwayStationInfo.setId(Objects.nonNull(id) ? Long.parseLong(id) : RandomUtil.getRandomNum(10000000, 99999999));
                        subwayStationInfo.setLineCode(jsonObject.getString("LINE_CODE"));
                        subwayStationInfo.setLineName(jsonObject.getString("LINE_NAME"));
                        subwayStationInfo.setSiteCode(jsonObject.getString("SITE_CODE"));
                        subwayStationInfo.setSiteName(jsonObject.getString("SITE_NAME"));
                        subwayStationInfo.setSiteIntroduced(jsonObject.getString("SITE_INTRODUCED"));
                        subwayStationInfo.setOperCode(jsonObject.getString("OPER_CODE"));
                        subwayStationInfo.setSitePic(jsonObject.getString("SITE_PIC"));
                        //请求高德  获取经纬度
                        String address = subwayStationInfo.getAddress();
                        InitProcessor();
                        GaoDeGeoArea gaoDeGeoArea = gaoDeAddressProcessor.processGeocoAddress(address, "JSON");
                        subwayStationInfo.setGdAddressCode(gaoDeGeoArea.getAdCode());
                        subwayStationInfo.setGdCountry(gaoDeGeoArea.getCountry());
                        subwayStationInfo.setGdProvince(gaoDeGeoArea.getProvince());
                        subwayStationInfo.setGdCity(gaoDeGeoArea.getCity());
                        subwayStationInfo.setGdCityCode(gaoDeGeoArea.getCityCode());
                        subwayStationInfo.setGdDistrict(gaoDeGeoArea.getDistrict());
                        subwayStationInfo.setGdLat(Double.valueOf(gaoDeGeoArea.getLat()));
                        subwayStationInfo.setGdLng(Double.valueOf(gaoDeGeoArea.getLng()));

                        //无法获取到街道信息 从逆编码中获取
                        //根据经纬度进行编码
                        String location = gaoDeGeoArea.getLng() + "," + gaoDeGeoArea.getLat();
                        GaoDeResGeoArea gaoDeResGeoArea = gaoDeAddressProcessor.processReverseCode(location, "all", "500", "公园|旅游景点|商场|购物中心|商务写字楼|政府及社会团体相关|政府机关相关|国家级机关及事业单位|住宅区|别墅|住宅小区|综合医院", "1", "JSON");
                        subwayStationInfo.setGdStreet(gaoDeResGeoArea.getTown());
                        subwayStationInfo.setGdStreetCode(gaoDeResGeoArea.getTownCode());
                        //解析Poi 封装成 map
                        JSONArray jsonArray = JSONArray.parseArray(gaoDeResGeoArea.getPois());
                        HashMap<String, ArrayList<Poi>> map = PoiParser.parseGaodeResponse(jsonArray);
                        //将 poi结果赋值给bean
                        FirstPoi<String> poi = PoiParser.filePoi(map, FirstPoi.class);
//                        System.out.println(poi);
                        subwayStationInfo.setPoi(poi);
                        //解析道路
                        subwayStationInfo.setNearRoad(JSON.toJSONString(Road.parseRoadForMysql(gaoDeResGeoArea.getRoads())));
                        //解析商圈
                        subwayStationInfo.setBusiness(JSON.toJSONString(Business.parseBusForMysql(gaoDeResGeoArea.getBusinessAreas())));
                        //获取版本 暂时手动赋值
                        subwayStationInfo.setVersion("2024-01-01");
                        log.info("获取到 {} 地铁站信息",subwayStationInfo.getSiteName());
                        return subwayStationInfo;
                    }
            ).collect(Collectors.toList());
            //执行insert 获取结果
            int num = subwayMapper.insertSubwayStationInfoDO(collect);
            return new CommonInsert<>(num,collect.size());
        } else {
            return new CommonInsert<>(0,-1);
        }
    }

    /**
     * 获取地体线路信息,从地铁站点表中获取
     */
    @Override
    public CommonInsert<SubwayLine> setSubwayLine() {
        List<SubwayLine> subwayLineInfo = subwayMapper.getSubwayLineInfo();
        ArrayList<SubwayLine> collect = new ArrayList<>();
        subwayLineInfo.forEach(
                subwayLine -> {
                    int startYear = RandomGenerator.getRandomYear(2012, 2022);
                    while (true) {
                        int endYear = RandomGenerator.getRandomYear(2012, 2022);
                        if (endYear >= startYear) {
//                            log.info("插入" + subwayLine.getLineName() + "地铁线路信息");
                            subwayLine.setBuildStartYear(String.valueOf(startYear));
                            subwayLine.setBuildFinishYear(String.valueOf(endYear));
                            subwayLine.setOpeningTime(subwayLine.getBuildFinishYear());
                            collect.add(subwayLine);
                            break;
                        }
                    }
                }
        );
        int num = subwayMapper.insertSubwayLineInfo(collect);
        return new CommonInsert<>(num,subwayLineInfo.size());
    }

    /**
     * 获取地铁出口和公交换乘信息
     */
    @Override
    public CommonInsert<SubwayTransitTransfer> setSubwayTransitTransfer(int page, int rows) {
        String transferUrl = "https://opendata.sz.gov.cn/api/29200_00403625/1/service.xhtml";
        HttpClient client = HttpClientHelper.createDefault();
        HashMap<String, Object> stationParmMap = new HashMap<>();
        stationParmMap.put("appKey", CustomLogServerConfig.OPENDATA_SZ_APP_KEY);
        stationParmMap.put("page", String.valueOf(page));
        stationParmMap.put("rows", String.valueOf(rows));
        JSONObject transferResponse = HttpClientHelper.sendJsonGetRequest(transferUrl, AddressConfig.ContentTypeJsonHeader, stationParmMap,
                ContentType.APPLICATION_JSON, client);
        String responseRow = transferResponse.getString("rows");
        if (Objects.nonNull(responseRow) && String.valueOf(rows).equals(responseRow)){
            JSONArray dataJsArray = transferResponse.getJSONArray("data");
            ArrayList<SubwayTransitTransfer> collect = new ArrayList<>();
            for (Object obj : dataJsArray) {
                SubwayTransitTransfer subwayTransitTransfer = new SubwayTransitTransfer();
                try {
                    JSONObject jsonObject = (JSONObject) obj;
                    subwayTransitTransfer.setLineCode(jsonObject.getString("LINE_CODE"));
                    subwayTransitTransfer.setSiteCode(jsonObject.getString("SITE_CODE"));
                    subwayTransitTransfer.setSiteOut(jsonObject.getString("SITE_OUT"));
                    subwayTransitTransfer.setBusName(jsonObject.getString("BUS_NAME"));
                    subwayTransitTransfer.setOperCode(jsonObject.getString("OPER_CODE"));
                    subwayTransitTransfer.setInfo(jsonObject.getString("INFO"));
                    subwayTransitTransfer.setInfoType(jsonObject.getString("INFO_TYPE"));
                    subwayTransitTransfer.setVersion("2024-01-01");
                    collect.add(subwayTransitTransfer);
                }catch (JSONException e){
                    e.printStackTrace();
                    log.error("error on parse json {}",obj.toString());
                }
            }
            int num = subwayMapper.insertSubwayTransitTransfer(collect);
            return new CommonInsert<>(collect.size(),num);
        }else {
            return new CommonInsert<>(-0,-1);
        }

    }

    /**
     * 新增地铁流量信息 后期使用ThreadExecutor 优化 该接口每天调用一次 目前用于离线场景
     * @param num 数量
     * @param date 生成日期
     * 生成逻辑 维护集合
     * 订单号不重复 查表
     * 同一天的用户id 不重复
     * 查询用户表
     */
    @Override
    public CommonInsert<SubwayGateSwipeDetail> mockSubwayTraffic(int num, String date, String type) {
        HashSet<UserInfo> userInfoSet = new HashSet<>();
        List<UserInfo> userInfoList = userMapper.selectAllUser();
        //todo 携带poi的对象占用很大内存 后期优化
        List<SubwayStationInfo> subwayStationList = subwayMapper.getAllSubwayStationInfo();
        //查询历史订单的订单信息并转化为Set
        HashSet<String> historyOrderSet = new HashSet<>(subwayMapper.getAllSubwayTrafficOrder());
//        HashSet<String> historyOrderSet = new HashSet<>();
        HashSet<String> orderSet = new HashSet<>();
        //结果集合
        ArrayList<SubwayGateSwipeDetail> trafficCollect = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            SubwayGateSwipeDetail subwayPayment = new SubwayGateSwipeDetail();
            while (true) {
                UserInfo userInfo = userInfoList.get(new Random().nextInt(userInfoList.size()));
                if (!userInfoSet.contains(userInfo)) {
                    userInfoSet.add(userInfo);
                    subwayPayment.setUserId(userInfo.getUserId());
                    subwayPayment.setStu(DateFormatUtil.isYoungPeople(userInfo.getBirthday(), 2024)); //学生票定义
                    subwayPayment.setDeformed(TrafficMocker.isDeformed(DateFormatUtil.isOldPeople(userInfo.getBirthday(), 2024)));
                    break;
                }
            }
            //生成订单号码 查询历史订单是否冲突
            while (true) {
                String orderId = RandomGenerator.generateRandomNumber(12);
                if (!orderSet.contains(orderId) && !historyOrderSet.contains(orderId)) {
                    orderSet.add(orderId);
                    subwayPayment.setOrderId(orderId);
                    break;
                }
            }
            //起始站和终点站 以及闸机定位 暂时不考虑同站进出的情况 换乘概率为 60 单线乘坐的概率为 40
            int stationTag = new Random().nextInt(100);
            if (stationTag < 60) { //必须不同线路不同站点
                //生成起始站点
                subwayPayment.setTransfer(true);
                SubwayStationInfo startStation = subwayStationList.get(new Random().nextInt(subwayStationList.size()));
                String startSiteCode = startStation.getSiteCode();
                String lineCode = startStation.getLineCode();
                subwayPayment.setStartSiteCode(startSiteCode);
                subwayPayment.setStartSiteName(startStation.getSiteName());
                subwayPayment.setStartLineCode(lineCode);
//                List<SubwayGateInfo> gateList = subwayMapper.getGateBySite(startSiteCode);
//                SubwayGateInfo startGate = gateList.get(new Random().nextInt(gateList.size()));
//                subwayPayment.setStartGateUnitCode(startGate.getGateGroupCode());
//                subwayPayment.setStartGateCode(startGate.getGateCode());
                //生成技结束站点
                while (true) {
                    SubwayStationInfo endStation = subwayStationList.get(new Random().nextInt(subwayStationList.size()));
                    if (!endStation.getSiteCode().equals(startSiteCode) && !endStation.getLineCode().equals(lineCode)) {
                        subwayPayment.setEndLineCode(endStation.getLineCode());
                        subwayPayment.setEndSiteName(endStation.getSiteName());
                        subwayPayment.setEndSiteCode(endStation.getSiteCode());
//                        List<SubwayGateInfo> endGateList = subwayMapper.getGateBySite(subwayPayment.getEndSiteCode());
//                        SubwayGateInfo endGate = endGateList.get(new Random().nextInt(endGateList.size()));
//                        subwayPayment.setEndGateCode(endGate.getGateCode());
//                        subwayPayment.setEndGateUnitCode(endGate.getGateGroupCode());
                        break;
                    }
                }
            } else { //同站上下车
                subwayPayment.setTransfer(false);
                List<String> lineList = subwayMapper.getAllLine();
                String line = lineList.get(new Random().nextInt(lineList.size()));
                List<SubwayStationInfo> stationInLineList = subwayMapper.getStationByLine(line); //同一条线路所有站点
                SubwayStationInfo startStation = stationInLineList.get(new Random().nextInt(stationInLineList.size()));
                subwayPayment.setStartSiteCode(startStation.getSiteCode());
                subwayPayment.setStartSiteName(startStation.getSiteName());
                subwayPayment.setStartLineCode(line);
                //下车点 同站
                while (true) {
                    SubwayStationInfo endStation = subwayStationList.get(new Random().nextInt(stationInLineList.size()));
                    if (!(Objects.equals(endStation.getSiteCode(), startStation.getSiteCode()))) {
                        subwayPayment.setEndSiteCode(endStation.getSiteCode());
                        subwayPayment.setEndSiteName(endStation.getSiteName());
                        subwayPayment.setEndLineCode(endStation.getLineCode());
                        break;
                    }
                }
            }
            //获取闸机编码
            List<SubwayGateInfo> startGateList = subwayMapper.getGateBySite(subwayPayment.getStartSiteCode());
            SubwayGateInfo startGate = startGateList.get(new Random().nextInt(startGateList.size()));
            subwayPayment.setStartGateCode(startGate.getGateCode());
            subwayPayment.setStartGateUnitCode(startGate.getGateGroupCode());
            List<SubwayGateInfo> endGateList = subwayMapper.getGateBySite(subwayPayment.getEndSiteCode());
            SubwayGateInfo endGate = endGateList.get(new Random().nextInt(endGateList.size()));
            subwayPayment.setEndGateCode(endGate.getGateCode());
            subwayPayment.setEndGateUnitCode(endGate.getGateGroupCode());
            //时间计算
            String endTime = RandomGenerator.generateRandomTimeStamp(date);
            subwayPayment.setEndTime(Timestamp.valueOf(endTime));
            long through = 0L;
            if (subwayPayment.isTransfer()) {
                through = 15 * 60 + new Random().nextInt(100 * 60 - 15 * 60);
            } else {
                through = 8 * 60 + new Random().nextInt(60 * 60 - 8 * 60);
            }
            //定义起始时间 离线和实时不同
            String startTime = type.equals("batch") ?  RandomGenerator.generateStartTime(endTime, through) :
                    DateFormatUtil.toYmdHms(System.currentTimeMillis());
            subwayPayment.setStartTime(Timestamp.valueOf(startTime));
            subwayPayment.setOrderTime(Timestamp.valueOf(RandomGenerator.generateStartTime(endTime, -2))); //订单推送
            //门票类型 购票地点 支付方式
            subwayPayment.setAliPlayActive(false); //后期判断
            if (TrafficMocker.isTicketOnline()){
                subwayPayment.setTicketType("二维码");
                if (TrafficMocker.isSZTUser()){
                    subwayPayment.setSwipeType("深圳通APP");
                    subwayPayment.setPaymentType(TrafficMocker.getOnlinePaymentType());
                }else {
                    subwayPayment.setSwipeType("支付宝乘车码");
                    subwayPayment.setAliPlayActive(TrafficMocker.isAppActActive()); //支付宝活动
                    if (subwayPayment.isAliPlayActive()){
                        subwayPayment.setAliPlayModelType(TrafficMocker.getAliPayActiveCode());
                    }
                    subwayPayment.setPaymentType("支付宝");
                }
            }else {
                subwayPayment.setTicketType("购票机SZT2024版线下票");
                subwayPayment.setSwipeType(null); //线下票不算刷码
                subwayPayment.setTicketLocation(subwayPayment.getStartSiteName() + "实体购票机器");
                subwayPayment.setPaymentType(TrafficMocker.getOfflinePaymentType(false)); //线下支付方式
            }
            // 金额计算
            BigDecimal orderAmount = TrafficMocker.calculateFare(through);
            subwayPayment.setOrderAmount(orderAmount);
            BigDecimal payment = orderAmount;
            if (subwayPayment.isStu()){
                payment = orderAmount.divide(BigDecimal.valueOf(2), 2, RoundingMode.HALF_UP);
            }
            if (subwayPayment.isDeformed()){
                payment = payment.subtract(BigDecimal.valueOf(1)).compareTo(BigDecimal.valueOf(0)) < 0
                        ? BigDecimal.valueOf(0) : payment.subtract(BigDecimal.valueOf(1)); //关爱通减免金额
                subwayPayment.setCarePassDeductionAmount(BigDecimal.ONE);
            }
            //支付宝活动
            if (subwayPayment.getPaymentType().equals("支付宝") && subwayPayment.isAliPlayActive() && subwayPayment.getAliPlayModelType()
                    .equals(1)){
                payment = payment.subtract(BigDecimal.valueOf(0.5)).compareTo(BigDecimal.ZERO) < 0 ?
                        BigDecimal.ZERO : payment.subtract(BigDecimal.valueOf(0.5));
                subwayPayment.setAlipayDeductionAmount(BigDecimal.valueOf(0.5));
            }
            subwayPayment.setOneCardReductionAmount(BigDecimal.ZERO);
            subwayPayment.setPaymentAmount(payment);
            subwayPayment.setPaymentTime(Timestamp.valueOf(RandomGenerator.generateStartTime(
                    String.valueOf(subwayPayment.getOrderTime()),-1)
            ));
            subwayPayment.setCreateTime(subwayPayment.getEndTime());
            subwayPayment.setPaymentSerialNumber(Long.valueOf(RandomGenerator.generateRandomNumber(15)));
            //处理未支付订单
            TrafficMocker.clearUnPaymentOrder(subwayPayment);
            if (subwayPayment.getPaymentTime() != null){
                subwayPayment.setUpdateTime(subwayPayment.getPaymentTime());
            }
            trafficCollect.add(subwayPayment);
            log.info("写入地铁订单: " + subwayPayment.getOrderId());
        }
        //执行写入
        int n = subwayMapper.insertSubwayTraffic(trafficCollect);
        return new CommonInsert<>(num,n);
    }

    /**
     * 生成闸机
     */
    @Override
    public CommonInsert<SubwayGateInfo> addGate() {
        ArrayList<SubwayGateInfo> gateCollect = new ArrayList<>();
        //闸机和出入口绑定  默认一个闸机组有4个闸机 每个闸机组对应一个出口
        //两种方式获取所有出口信息
        //从公交换乘信息中获取
        List<SubwayTransitTransfer> transferSiteOutList = subwayMapper.getAllGateWithSite();
        HashMap<String, String> tranSiteOutMap = new HashMap<>();
        for (SubwayTransitTransfer subwayTransitTransfer : transferSiteOutList) {
            tranSiteOutMap.put(subwayTransitTransfer.getSiteCode(),subwayTransitTransfer.getSiteOut());
        }
        //从地铁站点解析的交通服务poi中获取 地铁出入口属于poi交通运输服务的子标签
        //todo  一个出口对用一个闸机组
        List<String> stationList = subwayMapper.getAllStations();
        for (String station : stationList) {
            String transportation = subwayMapper.getTransportationBySite(station);
            //通过两种方式 解析地铁出入口
            HashSet<String> siteOutSet = new HashSet<>(); //对于每个地铁站构建一个set
            String tranSiteOutConnectStr = tranSiteOutMap.get(station);
            if (Objects.nonNull(tranSiteOutConnectStr)){
                tranSiteOutConnectStr = tranSiteOutConnectStr.replaceAll("/","-").replaceAll(",","-").replaceAll("、","-")
                        .replaceAll("，","-"); //需要枚举出口名称
                if (station.equals("260022")){
                    System.out.println(tranSiteOutConnectStr);
                }
                String partten1 = "([a-zA-Z0-9]+)出入口";
                String partten2 = "([a-zA-Z]+)\\d+出入口";
                String pattern3 = "[a-zA-Z]";
                Pattern p1 = Pattern.compile(partten1);
                Pattern p2 = Pattern.compile(partten2);
                Pattern p3 = Pattern.compile(pattern3);
                for (String s : tranSiteOutConnectStr.split("-")) {
                    Matcher m1 = p1.matcher(s);
                    Matcher m2 = p2.matcher(s);
                    Matcher m3 = p3.matcher(s);
                    if (m1.find()){
                        siteOutSet.add(m1.group(1).toUpperCase());
                        continue;
                    }
                    if (m2.find()){
                        siteOutSet.add(m2.group(1).toUpperCase());
                        continue;
                    }
                    if (m3.find()){
                        siteOutSet.add(m3.group().toUpperCase());
                    }
                }
            }
            //第二种
            JSONObject transportJsObj = JSONObject.parseObject(transportation);
            if (Objects.nonNull(transportJsObj)) {
                transportJsObj.values().forEach(
                        tranJs -> {
                            if (Objects.equals(station, "260022")){
                                System.out.println(tranJs);
                            }
                            JSONObject tranJsObj = JSONObject.parseObject(JSON.toJSONString(tranJs));
                            if (Objects.nonNull(tranJsObj.getString("type")) && tranJsObj.getString("type").equals("交通设施服务;地铁站;出入口")) {
                                String nameStr = tranJsObj.getString("name");
                                String partten = "地铁站([a-zA-Z]+\\d*)口";
                                Pattern p = Pattern.compile(partten);
                                Matcher m = p.matcher(nameStr);
                                if (m.find()) {
                                    String matchSiteOut = m.group(1);
                                    siteOutSet.add(matchSiteOut.toUpperCase());
                                }
                            }
                        }
                );
            }
            //todo
            for (String siteOut : siteOutSet) { //每个闸机出口对应一个闸机组
                String gateGroupCode = station + "-" + siteOut;
                for (int i = 0; i < 4; i++) {
                    SubwayGateInfo subwayGateInfo = new SubwayGateInfo();
                    subwayGateInfo.setGateGroupCode(gateGroupCode);
                    subwayGateInfo.setGateStationCode(station); //闸机编码 地铁编码-出口编码-闸机组编码-6位随机值
                    subwayGateInfo.setGateCode(subwayGateInfo.getGateGroupCode() + "-" + "00" + (i+1) + "-" + RandomGenerator.generateRandomNumber(6));
                    subwayGateInfo.setCorporation("深铁置业有限公司");
                    subwayGateInfo.setIfSupportAliPay(true);
                    subwayGateInfo.setIfSupportOnceTicket(true);
                    subwayGateInfo.setSubwayExport(siteOut);
                    subwayGateInfo.setOpenTime(null); //暂时不可用
                    subwayGateInfo.setMaintenanceCycle("30");
                    subwayGateInfo.setLastMaintenanceTime(Timestamp.valueOf(RandomGenerator.generateRandomTimeStamp("2024-03-01")));
                    subwayGateInfo.setCreateTime(Timestamp.valueOf(DateFormatUtil.toYmdHms(System.currentTimeMillis())));
                    gateCollect.add(subwayGateInfo);
                }
            }
        }
        int result = subwayMapper.insertGate(gateCollect);
        return new CommonInsert<>(gateCollect.size(),result);
    }


//    public static void main(String[] args) {
//        SubwayServiceImpl subwayService =   new SubwayServiceImpl();
//        subwayService.setSubwayStationInfo(1,1);
//    }
}